/*
 * Repository.hpp
 *
 *  Created on: 21/09/2011
 *      Author: marcio
 */

#ifndef REPOSITORY_HPP_
#define REPOSITORY_HPP_

#include "repository.h"

// a repository
class Repository {
private:
	// of its chained list
	void* base;      // of the buffers' chained list
	size_t step;     // number of elements allocated when this repository is empty
	size_t elemz;

	Repository(){
		base = NULL;
	}
public:
	static Repository* newRep(size_t step, size_t elemz);

	// get an element from a specified repository
	void* getFromRep();

	// release a specified element using the specified repository
	void releaseFrom( void* b);

	// free memory space used by a specified repository
	static void freeRep(Repository* r);

	// free memory space used to manage repositories
	static int freeBaseRep();
};

Repository* Repository::newRep(size_t step2, size_t elemz2){
	Repository* r = new Repository();
	r->base = newRepo(step2, elemz2 );
	return r;
}

// get an element from a specified repository
inline void* Repository::getFromRep(){
	void* ret;
	getFromRepo(ret);
	return ret;
}

// release a specified element using the specified repository
inline void Repository::releaseFrom( void* r){
	release(base , r);
}

// free memory space used by a specified repository
void Repository::freeRep(Repository* r){
	freeRepo(r->base);
}

// free memory space used to manage repositories
int Repository::freeBaseRep(){
	freeBaseRepo();
}


#endif /* REPOSITORY_HPP_ */
